package com.sql_sys;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class test 
{

    public static void main (String[] args) throws ClassNotFoundException, SQLException 
    {

        try 
        {

            Class.forName ("com.mysql.cj.jdbc.Driver") ;  // 加载 MySQL 驱动

            System.out.println ("数据库驱动加载成功") ;

        } 

        catch (ClassNotFoundException e) 
        {

            e.printStackTrace () ;

            System.out.println ("数据库驱动加载失败") ;

        }

        String url = "jdbc:mysql://localhost:3306/school" ;

        String user = "root" ;

        String password = "123456" ;

        Connection conn = null ;

        try
        {

            conn = DriverManager.getConnection (url , user , password) ;

            System.out.println ("数据库链接成功") ;

        }

        catch (SQLException e)
        {

            e.printStackTrace () ;

            System.out.println ("数据库链接失败") ;
        }

        conn.close () ;
        
    }
    
}
